Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Type Model Visitor

Project description

TMV (Type Model Visitor)

Visitor for type models using typing annotations.

What's inside?

The package contains an abstract Visitor class which needs by-type methods implementation. Only (some of) the standard types are supported:

  • primitives (int, str, float, bool)
  • iterables
  • mappings
  • tuples
  • dataclasses
  • Enum, Any, Tuple, Union, Optional, Literal, NewType
  • soon TypedDict (PEP 589), Annotated (PEP 593), etc.

Unsupported types are handled in unsupported method, of which default implementation raises Unsupported exception.

Visitor offers support for custom types through 2 methods ìs_custom and custom. The return value of is_custom is passed to custom when evaluated to True; it's thus convenient to use an optional return type. Customs types are handled before others classes like dataclasses or enumerations (to enable custom handling for them).

See apischema for concrete use of the package


  • If an abstract class was at first considered for Visitor implementation, raising NotImplementedError has been chosen because it enable an easier use, especially in case of partial implementation (which would imply to overwrite with NotImplementedError in case of ABC inheritance)
  • For convenience, inheritance is not handled in this project. In fact, if __bases__ and even __orig_bases__ could be used, this would raises other issues like multiple inheritance. Moreover, some implementation could rely on __init__ method (it's the case apischema from which this project was originally extracted), and inheritance makes things fuzzy on this point.
  • Customs type could be handled in an overwrite of unsupported method, but this would make impossible to handle custom dataclasses, that's why a dedicated method is used

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tmv, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size tmv-0.1.3-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size tmv-0.1.3.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page