Comments (4)
Right now the pattern
attribute is strictly a string...
https://github.com/encode/typesystem/blob/master/typesystem/fields.py#L106
I'd be very happy to:
- Accept a PR that switched that to allowing either a string or a regex.
- Added a
pattern_regex
property on the String field, which is used to store the compiled pattern. - Switch the validation to use the compiled
pattern_regex
to perform the matching.
So I think __init__
would look something like this...
if pattern is None:
self.patten is None
self.pattern_regex is None
elif isinstance(pattern, str):
self.pattern = pattern
self.pattern_regex = re.compile(pattern)
elif isinstance(pattern, re.Pattern):
self.pattern = pattern.pattern
self.pattern_regex = pattern
from typesystem.
Similar to this we'll also want beter support for customizing error messages, so that eg...
# Match valid variable names like 'someFunctionName123'
variable_name = typesystem.String(
pattern="^a-zA-Z_[a-zA-Z0-9_]*$",
errors={"pattern": "Must be a valid variable name."}
)
But we'll handle that under #28
from typesystem.
i'll cook a pr. it's gonna be simpler than your suggestions.
from typesystem.
Sure thing
However you implement, you'll want to make sure that the pattern
attribute always gets set to a plain string - we inspect that attribute when generating JSON schema documents.
from typesystem.
Related Issues (20)
- Test failures on python3.8/python3.9
- `Email` field
- `URL` field
- `IPAddress` field
- `File` field HOT 1
- `Image` field HOT 1
- References are broken for JSON schema (0.4.0) HOT 5
- Quickstart example presented in the README does not work HOT 1
- UnboundLocalError: local variable 'field' referenced before assignment
- Serialization of reference fields in composite fields HOT 1
- Time fields deserialized as strings instead of datetime objects HOT 1
- Dynamic Choice fields
- fields.Choice to include list of choices in validation error message HOT 1
- Nested `Schema` instantiation
- Cross field and conditional validation
- datetime incompatibility with JSON schema and OpenAPI specification
- IntegerField allows string HOT 1
- Generation of typesystem classes from orm/sqlalchemy models (On-the-fly or command based)
- Adding `title` and `description` to JSON Schema for Fields
- HTML Radiobutton field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typesystem.