Advertisement
mwchase

Two Ways to Implement a Feature Nobody Asked For

Sep 3rd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import typing
  2.  
  3. import data_types  # New module!
  4.  
  5. R = typing.TypeVar('R')
  6. E = typing.TypeVar('E')
  7.  
  8. class Result(data_types.Data, typing.Generic[R, E]):
  9.  
  10.     class Constructors(data_types.Constructors):
  11.         # Constraints are required at runtime, but may not be enforced
  12.         Ok = R,
  13.         Err = E,
  14.  
  15. ---
  16.  
  17. import typing
  18.  
  19. import data_types  # New module!
  20.  
  21. R = typing.TypeVar('R')
  22. E = typing.TypeVar('E')
  23.  
  24. class Result(data_types.Data, typing.Generic[R, E]):
  25.  
  26.     class Constructors(data_types.Constructors):
  27.         # Constraints may not exist, but mypy should fail if they don't
  28.         Ok: R,
  29.         Err: E,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement