I'm giving a tutorial. It's gonna be a bunch of fun. Here's what I'll be covering and what you can do to prep.
- (1.5h) 42 Tips and Tricks
- (0.5h) 20 Django Tips
| from dataclasses import dataclass | |
| from typing import Protocol, Optional, TypeVar, Type | |
| class Animal(Protocol): | |
| name: str | |
| @dataclass | |
| class Mammal: |
| from pathlib import Path | |
| def main(): | |
| icon = Path('/favicon.png') | |
| static = Path('/static') | |
| result = static / icon | |
| print(str(result)) | |
| """ | |
| Using an alias for a PEP 593 Annotation with multiple arguments. | |
| I'm rewriting my injector. | |
| I currently put the injector information in dataclass field metadata. | |
| I'd like to allow other callables such as functions, so I'm looking at PEP 593 Annotations, similar to what [the inject package](https://github.com/alecthomas/injector/blob/master/injector/__init__.py#L1116) does. | |
| My injection though needs zero or more arguments, sort of like an RxPY pipeline. | |
| # Update 1: Changed from Markdown science fiction to using code in a running test |
| from dataclasses import dataclass | |
| from wired import ServiceRegistry | |
| @dataclass | |
| class CustomerOne: | |
| name: str | |
I'm giving a tutorial. It's gonna be a bunch of fun. Here's what I'll be covering and what you can do to prep.
| """ | |
| Example of "Explicitly declaring implementation" | |
| PEP 544 says you can state that an implementation supports a protocol by | |
| `subclassing the protocol <https://www.python.org/dev/peps/pep-0544/#explicitly-declaring-implementation>`_. | |
| It also says: "If one omits Protocol in the base class list, this would | |
| be a regular (non-protocol) class that must implement Sized." | |
| In the implementation below, ``FrenchPerson`` says that it implements |
| from os.path import abspath, dirname, join | |
| from examples.usage.csr.bottle import route, run, static_file, template | |
| STATIC_DIR = abspath(join(dirname(__file__), 'static')) | |
| @route('/static/<filename>') | |
| def server_static(filename): | |
| return static_file(filename, root=STATIC_DIR) |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Hello Bulma!</title> | |
| <link rel="stylesheet" href="static/bulma.css"> | |
| </head> | |
| <body> | |
| <section class="section"> |
| """ | |
| I'm interested Python and the Modern Web. Including, a modern | |
| approach to templating: developer-focused, closer to Python, | |
| where code quality tools can help. Draft: | |
| https://viewdom-wired.readthedocs.io/en/latest/why.html | |
| I'm working on pluggable "components", as that link shows. Normally | |
| I'd throw zope.interface at it, but PEP 544 Protocols is more realistic: | |
| mypy support by default, some IDE integration to help DX, etc. |
| """ | |
| https://github.com/python/mypy/issues/4717#issuecomment-454609539 | |
| Hi Glyph, thanks for reading. This is going to take a while. | |
| I'm interested in pluggable systems. Specifically a better Sphinx rendering | |
| layer, which I've spent a lot of time on. Recently I've worked on Michael | |
| Merickel's wired: | |
| https://wired.readthedocs.io/ |