-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a great way to do something without overriding metaclass.
- Loading branch information
1 parent
06061f3
commit d38105c
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2024 RenChu Wang - All Rights Reserved | ||
|
||
from typing import Any | ||
|
||
|
||
class Super1: | ||
@classmethod | ||
def __init_subclass__(cls, **kwargs: Any) -> None: | ||
print(cls, kwargs) | ||
|
||
|
||
class Sub1(Super1): | ||
pass | ||
|
||
|
||
class Sub2(Super1, param="hello", argument=123): | ||
pass | ||
|
||
|
||
class Super2: | ||
@classmethod | ||
def __init_subclass__(cls, required: str) -> None: | ||
print(cls, required) | ||
|
||
|
||
# Would fail: | ||
# TypeError: Super2.__init_subclass__() missing 1 required positional argument: 'required' | ||
# class Sub3(Super2): | ||
# pass | ||
|
||
|
||
class Sub4(Super2, required="yes"): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
Sub1() | ||
Sub2() | ||
# Sub3() | ||
Sub4() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Computation fundamentals | ||
|
||
There are 2 main components in computing, data (measured by space complexity) and compute (measured by time complexity). | ||
|
||
I theorize that | ||
Data = entities, storage, intrinsically exists | ||
Compute = mutation on data | ||
|
||
Data is more fundamental than computation, because computation are performed on data (data = symbol, compute = instruction in Turning machine). | ||
|
||
Think of the types of data as Markov, then a library / app is just moving on a path on this Markov state / graph. This state is exactly a Turing machine’s state as I can ask TM to simulate a function for me. | ||
|
||
Even transmitting a packet counts as computation, because it's changing state (location) of a piece of data. | ||
|
||
How do abstractions come into play? | ||
|
||
- I think it's just types of data and the type of compute (abstract, reasoned with invariance) that can be performed on them. Considering that every function is data -> compute -> data, abstraction in terms of breaking down functions are just composing data into intermediate representation, and abstract interfaces are shared traits of different data + specialized compute for each kind of data. | ||
- Abstractions are just using computation to transform underlying data into the same mathematic model. Compiler optimizing this away = 0 cost. Some data structures might happen to have a better complexity but those are implementation details. |