Redesigning canonicalization: the fundamental (internal) overhaul we need
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 15/100
Piste de recherche
Start by reading src/hypothesis_jsonschema/_canonicalise.py, especially canonicalish(), merged(), and the numeric-bound helpers, to understand the current canonicalization design. The issue calls for a from-scratch rewrite covering immutable schema objects, reference handling, version-specific parsing, and set operations; done means those pieces support newer schema versions and recursive strategies, with behavior validated across the existing project tests.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Background
hypothesis-jsonschema is basically just a function which maps a json schema to a Hypothesis strategy for generating instances which conform to that schema... and a few internal helpers.
The basic problem is that there are very many eqivalent ways to express the same set of allowed objects, including many where the obvious translation to a strategy is terribly inefficient. We therefore start by "canonicalizing" the schema: taking the intersection or union of overlapping parts (as appropriate), and generally transforming the schema so that it expresses the same constraints but is as easy to convert to an efficient strategy as possible.
So what needs to change?
I wrote most of hypothesis-jsonschema about four years ago, and it never graduated from beta. There are some fundamental design flaws in how we deal with both recursive references and schema versioning, as well as some implementation issues where the organic growth of the code has left it slower and harder to understand than it ought to be. We'll also want to support schema versions newer than draft-07, which are now in common use.
I think this basically requires a from-scratch rewrite of the canonicalization logic. Happily, I learned a lot about what (not) to do last time around, so the next version can be substantially cleaner and I don't expect that we'd need to do this again. The rewrite could be in Python; or it could easily be extracted to Rust - performance challenges led to the omission of several useful rewrite passes, and the interface is "(serialized?) json schema in, (serialized?) json schema out" with no complicated control-flow or handoff.
A sketch of the current design
canonicalish(), which takes a schema and runs many imperative modifications to handle various subtypes of schemamerged(), which takes n schemas and returns their intersection (orNone, if infeasible)- some helpers to compute numeric bounds expressed by a schema
The design I want
Represent everything with objects!
- A schema (or subschema) is represented as an immutable object. Along with the contents of the (sub)schema, this should contain a reference to the top-level schema (possibly
self) to allow for resolution of references. The pair of(root schema, json pointer)stably and uniquely identifies eachSchemaobject - use memoization for improved performance. - Create subclasses of
Schemafor each major subtype of schemas - types, all_of, any_of, etc.; and version-specific variants where needed. Parsing a schema which permits multiple types should automatically convert to anyof over those types and allof over any other constraints. This "splitting" step is really important! - Identify all referenced subschemas, i.e. locations which are pointed-to from elsewhere. After a first pass at canonicalization, inline any pointed-to subschemas which do not themselves contain references. Repeat until there are no such subschemas - now, any reference left must be recursive and we can convert to a recursive strategy with
st.deferred(). - Give our schema objects explicit
.intersection()and.union()methods. Also implment the other set methods based on these; we often want (e.g.) subtraction in practice.
- Langage dominant
- Python
- Étoiles
- 281
- Forks
- 35
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python-jsonschema/hypothesis-jsonschema
-
Missing test files in Pypi releasePeut-être pris @blouirts123 l’a pris il y a 49 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
-
Shouldn't PKG-INFO Homepage point to https://github.com/python-jsonschema/hypothesis-jsonschema ?Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 58/100
python-jsonschema/hypothesis-jsonschema#114 · 1 commentaire ·
-
Push release tags to github?Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 55/100
python-jsonschema/hypothesis-jsonschema#113 · 1 réaction ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
Toutes les issues de python-jsonschema/hypothesis-jsonschema
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
Techiebutler/freeframe#687 ·
Les mainteneurs répondent en général sous 1 jour
-
bug verbose GC
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
IBM/javacore-analyser#677 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
Les mainteneurs répondent en général sous 2 jours
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
NousResearch/hermes-agent#163932 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePeut-être pris @Beehtrix l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
zilliztech/memsearch#907 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour