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

Exception in episode 1 #10

Open
markgdawson opened this issue Dec 8, 2020 · 1 comment
Open

Exception in episode 1 #10

markgdawson opened this issue Dec 8, 2020 · 1 comment

Comments

@markgdawson
Copy link
Collaborator

Mixing the concepts of exception and inheritance could be confusing here. Could introduce inheritance first, then introduce the use case of exception as a use of that.

Something like:

class MyArray(numpy.ndarray):
  pass

followed by

a = MyArray(shape=(10,10))
type(a) # shows MyArray
isinstance(a, MyArray)
isinstance(a, np.ndarray)

Would be very nice if we could find an example like this which could be extended (i.e. by adding a body to the class) in later episodes?

@edbennett
Copy link
Member

I agree that it would be good to disentangle these two points. The only reason I used exceptions here is because it's the main place in the Python standard library (that I could find) where inheritance was used significantly, and in ways that could be easily demonstrated and be found useful.

My concern with the proposed fix is that now we have introduced both class definitions and subclass definitions in a single line, whereas the aim of this episode was to use existing classes but not define any fresh ones. We'd be replacing one mix of concepts with another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants