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

List of potential improvements/inclusions #6

Open
21 tasks
ES-Alexander opened this issue Aug 12, 2020 · 2 comments
Open
21 tasks

List of potential improvements/inclusions #6

ES-Alexander opened this issue Aug 12, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request exercises Relevant to exercises notes Relevant to lesson notes

Comments

@ES-Alexander
Copy link
Owner

ES-Alexander commented Aug 12, 2020

  • f strings (including self-documenting with f'{var=}')
  • import this (zen of Python)
  • no need to inherit from object (already done implicitly)
  • functools.wraps for keeping docstring and metadata for decorated functions
  • __class__.__name__ in __repr__ definitions (and __str__ if the name makes sense to display)
  • define at least a __repr__, because __str__ falls back on it if undefined
  • __repr__ should be unambiguous, __str__ should be readable
  • good practice to define a base exception for distributed packages
  • copy module copy and deepcopy functions work on arbitrary objects (including custom classes)
  • comprehensions are faster and generally more efficient than manual creation
  • abs.ABC doesn't allow instantiation of the base class, and raises an error if methods aren't overridden instead of at call time (specifically helpful for instantiable classes, although likely most abstract classes are intended to be instantiable)
  • typing.NamedTuple is a memory-efficient shortcut to making immutable classes with a free __repr__ method, named access, and iterability, and reasonably nice definition syntax
  • types.SimpleNamespace is a dictionary with dot-accessible keys
  • instance properties 'shadow' class properties with the same name (the instance gets asked first, and used unless explicitly called as obj.class.prop)
  • factory functions are used to create standard/common instances with different parameters to those normally required (e.g. a VideoWriter from a stream (internal/measurable framerate) instead of from user-generated images)
  • make sure @Property is mentioned - setters and getters give actual control over what's accessible to the public interface (although internals are still technically findable/accessible)
  • dictionary updates with .update, and creation with defaults {'default': 3, **override}
  • tkinter -> tkinter.ttk (more modern and usable widgets)
  • underscores in numbers are ignored (can be used for visual separation)
  • 3.8 has positional-only and keyword-only arguments (preceded by special arguments '/' and '*') -> raise TypeError if caller specifies a positional only argument as a keyword
  • methods defined in a class scope can use class-variables as default values, but can only be used within the method definition if a reference is provided to the class/instance
@ES-Alexander ES-Alexander added enhancement New feature or request notes Relevant to lesson notes exercises Relevant to exercises labels Aug 12, 2020
@ES-Alexander ES-Alexander self-assigned this Aug 12, 2020
@ES-Alexander
Copy link
Owner Author

  • Exception wrapping (raise from), as per article and post

@ES-Alexander
Copy link
Owner Author

  • dataclasses
  • generators and coroutines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request exercises Relevant to exercises notes Relevant to lesson notes
Projects
None yet
Development

No branches or pull requests

1 participant