Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement type hinting for 3.11, support simple Protocols, clean up internals and document (rev2) #6

Merged
merged 16 commits into from
Jun 18, 2024

Conversation

autumnjolitz
Copy link
Owner

@autumnjolitz autumnjolitz commented Jun 17, 2024

  • Rename Atomic to AtomicMeta to signify that it is a metaclass

    • there’s no way to represent with type hints a “type T that is a metaclass of M” and also be able to use it as Type[T]
  • Add BaseAtomic into the types produced by AtomicMeta which allows for a fast isinstance() checks and representing in a type hinter!

    • one can put on the BaseAtomic fields that actually are on the metaclass to further the type checker fiction/inability to handle metaclass representation.
  • Make about.py contain a parsed version tuple using the packaging project and a pre-processing phase in setuptools

    • move the about.py-writing to a function so only the act of a attr: callable would trigger it
  • Add doctests to pytest discovery

    • this ensures that code in doc strings actually works 😅
  • Remove to_json everywhere except on the actual type-class instance (non-inheritable to class instances)

    • __json__ is a lot less invasive, obvious to override and won’t occupy a public variable name unlike to_json
  • Enhance asjson to handle instruct's exception types

  • Add __json__ outputs for TypeError, ValueError respectively

  • the result type object of parse_typedef(List[Union[str, int]]) -> Type[List[Union[str, int]]] now can be instantiated and it will attempt to best effort intercept incorrect types (i.e. when appending a value to a List[T] or setting a key on a Mapping).

    • TODO: check Set[Union[int, str]]for.add`
  • parse_typedef(Literal[1,2]) returns a single type now 😌 (used to be each literal value had its own unique types 😰)

  • SimpleBase._create_invalid_type now extends the list of allowed types in the error message for Literal[…] values

  • TODO: allow parse_typedef to work on a class that inherits Protocol

    • use the annotations to verify attribute types
    • If an annotation has a corresponding value, check equality
    • iterate through functions, ensure that an attribute that is callable with that signature (if possible)

@autumnjolitz autumnjolitz force-pushed the bugfix/master/relax-restrictions-backport branch from 65ac67e to a3363fe Compare June 17, 2024 23:47
@autumnjolitz autumnjolitz force-pushed the bugfix/master/relax-restrictions-backport branch from 45a89d3 to f716e85 Compare June 18, 2024 00:20
@autumnjolitz autumnjolitz merged commit 6c8bf41 into master Jun 18, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant