workspace
stringclasses
1 value
channel
stringclasses
1 value
sentences
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
sentence_id
stringlengths
44
53
timestamp
float64
1.5B
1.56B
__index_level_0__
int64
0
106k
pythondev
help
i know Python looks up the class tree from the child upwards, not the other way around
2019-03-13T18:39:23.498900
Tasha
pythondev_help_Tasha_2019-03-13T18:39:23.498900
1,552,502,363.4989
13,221
pythondev
help
well, if you have an instance of "ChildError"
2019-03-13T18:40:10.500100
Kendra
pythondev_help_Kendra_2019-03-13T18:40:10.500100
1,552,502,410.5001
13,222
pythondev
help
then python goes through the `except` statements
2019-03-13T18:40:32.500500
Kendra
pythondev_help_Kendra_2019-03-13T18:40:32.500500
1,552,502,432.5005
13,223
pythondev
help
<@Tasha> this is basically just inheritance. Python will catch the error, since it's in a `try` block, and then see if you want to catch that particular error by checking your `except` blocks in sequence (much like if/elif/else blocks). Every class in Python has a linearized chain of ancestors. This linearization is determined through a process called "Method Resolution Order" (MRO), which can be tricky, but there's a great talk by Raymond Hettinger called "Super Considered Super" which does a great job of explaining it. With the MRO chain established, Python can quickly and easily check to see if you want to catch that error
2019-03-13T18:40:40.500800
Ashley
pythondev_help_Ashley_2019-03-13T18:40:40.500800
1,552,502,440.5008
13,224
pythondev
help
and looks if class in `except` is in `ChildError`'s `__bases__`
2019-03-13T18:41:32.501100
Kendra
pythondev_help_Kendra_2019-03-13T18:41:32.501100
1,552,502,492.5011
13,225
pythondev
help
There’s also this, which is a bit tough to read but technically how the MRO sausage is made: <https://www.python.org/download/releases/2.3/mro/>
2019-03-13T18:41:59.501800
Carina
pythondev_help_Carina_2019-03-13T18:41:59.501800
1,552,502,519.5018
13,226
pythondev
help
```In [1]: class ParentException(Exception): pass In [2]: class ChildException(ParentException): pass In [3]: exc = ChildException() In [4]: exc.__class__.__bases__ Out[4]: (__main__.ParentException,)```
2019-03-13T18:42:28.502800
Kendra
pythondev_help_Kendra_2019-03-13T18:42:28.502800
1,552,502,548.5028
13,227
pythondev
help
In terms of your example, it would be caught (assuming you raised the exception in the try block) because the child exception _is_ its parent in a certain sense. It's just an extension on the parent
2019-03-13T18:42:34.503100
Ashley
pythondev_help_Ashley_2019-03-13T18:42:34.503100
1,552,502,554.5031
13,228
pythondev
help
If python determines that you didn't want to catch that error, it just lets it get raised as if it wasn't in a try block
2019-03-13T18:43:39.504200
Ashley
pythondev_help_Ashley_2019-03-13T18:43:39.504200
1,552,502,619.5042
13,229
pythondev
help
in approximation it's like doing `isinstance(exc, SomeException)`
2019-03-13T18:43:44.504300
Kendra
pythondev_help_Kendra_2019-03-13T18:43:44.504300
1,552,502,624.5043
13,230
pythondev
help
thanks very much <@Ashley>
2019-03-13T18:46:22.504900
Tasha
pythondev_help_Tasha_2019-03-13T18:46:22.504900
1,552,502,782.5049
13,231
pythondev
help
but this type of i inheritance only works with Exceptions..?
2019-03-13T18:47:30.505700
Tasha
pythondev_help_Tasha_2019-03-13T18:47:30.505700
1,552,502,850.5057
13,232
pythondev
help
all classes
2019-03-13T18:47:53.505900
Kendra
pythondev_help_Kendra_2019-03-13T18:47:53.505900
1,552,502,873.5059
13,233
pythondev
help
``` class Parent(): pass class Child(Parent): message = "hello" print(Parent().message) ```
2019-03-13T18:50:08.508200
Tasha
pythondev_help_Tasha_2019-03-13T18:50:08.508200
1,552,503,008.5082
13,234
pythondev
help
``` Traceback (most recent call last): File "/tmp/sessions/7ceb9d9608012ec8/main.py", line 10, in &lt;module&gt; print(Parent().message) AttributeError: 'Parent' object has no attribute 'message' ```
2019-03-13T18:50:22.508600
Tasha
pythondev_help_Tasha_2019-03-13T18:50:22.508600
1,552,503,022.5086
13,235
pythondev
help
I know this is not the same
2019-03-13T18:50:37.509200
Tasha
pythondev_help_Tasha_2019-03-13T18:50:37.509200
1,552,503,037.5092
13,236
pythondev
help
As <@Kendra> said, this is all classes in Python. It's just how inheritance works. Python needed a way to linearize inheritance in the event that a class inherits from multiple classes at once, so they came up with MRO. MRO can also be utilized for things like dependency injection, which is fairly advanced, but very useful
2019-03-13T18:50:52.510000
Ashley
pythondev_help_Ashley_2019-03-13T18:50:52.510000
1,552,503,052.51
13,237
pythondev
help
<@Tasha> changing the child does not change the parent
2019-03-13T18:51:21.510800
Ashley
pythondev_help_Ashley_2019-03-13T18:51:21.510800
1,552,503,081.5108
13,238
pythondev
help
ok greast
2019-03-13T18:51:22.510900
Tasha
pythondev_help_Tasha_2019-03-13T18:51:22.510900
1,552,503,082.5109
13,239
pythondev
help
That's part of the reason you would inherit
2019-03-13T18:51:46.511700
Ashley
pythondev_help_Ashley_2019-03-13T18:51:46.511700
1,552,503,106.5117
13,240
pythondev
help
Think of a class called "Fruit"
2019-03-13T18:51:57.512200
Ashley
pythondev_help_Ashley_2019-03-13T18:51:57.512200
1,552,503,117.5122
13,241
pythondev
help
ok
2019-03-13T18:52:05.512600
Tasha
pythondev_help_Tasha_2019-03-13T18:52:05.512600
1,552,503,125.5126
13,242
pythondev
help
It has all the info you could have about, and all the things you could do with a generic fruit, but it isn't any fruit in particular
2019-03-13T18:52:33.513400
Ashley
pythondev_help_Ashley_2019-03-13T18:52:33.513400
1,552,503,153.5134
13,243
pythondev
help
right
2019-03-13T18:52:43.513700
Tasha
pythondev_help_Tasha_2019-03-13T18:52:43.513700
1,552,503,163.5137
13,244
pythondev
help
Then inherit from it and make an Apple class
2019-03-13T18:52:53.514200
Ashley
pythondev_help_Ashley_2019-03-13T18:52:53.514200
1,552,503,173.5142
13,245
pythondev
help
That class gets all the things from the Fruit class, but has the opportunity to add or adjust things
2019-03-13T18:53:25.515100
Ashley
pythondev_help_Ashley_2019-03-13T18:53:25.515100
1,552,503,205.5151
13,246
pythondev
help
``` class Fruit(): taste = "sweet" color = "defualt" class Apple(Fruit): color = "red" ```
2019-03-13T18:53:51.515900
Tasha
pythondev_help_Tasha_2019-03-13T18:53:51.515900
1,552,503,231.5159
13,247
pythondev
help
Close
2019-03-13T18:54:04.516200
Ashley
pythondev_help_Ashley_2019-03-13T18:54:04.516200
1,552,503,244.5162
13,248
pythondev
help
Not all fruits are sweet, but you get the idea
2019-03-13T18:54:17.516600
Ashley
pythondev_help_Ashley_2019-03-13T18:54:17.516600
1,552,503,257.5166
13,249
pythondev
help
ok
2019-03-13T18:54:23.516800
Tasha
pythondev_help_Tasha_2019-03-13T18:54:23.516800
1,552,503,263.5168
13,250
pythondev
help
so how do i use Fruit()
2019-03-13T18:54:30.517100
Tasha
pythondev_help_Tasha_2019-03-13T18:54:30.517100
1,552,503,270.5171
13,251
pythondev
help
and some how call all its child classes
2019-03-13T18:54:39.517400
Tasha
pythondev_help_Tasha_2019-03-13T18:54:39.517400
1,552,503,279.5174
13,252
pythondev
help
Why would you want to?
2019-03-13T18:54:56.517800
Ashley
pythondev_help_Ashley_2019-03-13T18:54:56.517800
1,552,503,296.5178
13,253
pythondev
help
except Fruit as err
2019-03-13T18:55:10.518400
Tasha
pythondev_help_Tasha_2019-03-13T18:55:10.518400
1,552,503,310.5184
13,254
pythondev
help
lol
2019-03-13T18:55:10.518700
Tasha
pythondev_help_Tasha_2019-03-13T18:55:10.518700
1,552,503,310.5187
13,255
pythondev
help
The parent doesn't usually need to know about its descendents
2019-03-13T18:55:48.519600
Ashley
pythondev_help_Ashley_2019-03-13T18:55:48.519600
1,552,503,348.5196
13,256
pythondev
help
yes thats right
2019-03-13T18:55:55.520000
Tasha
pythondev_help_Tasha_2019-03-13T18:55:55.520000
1,552,503,355.52
13,257
pythondev
help
But yes
2019-03-13T18:55:55.520100
Ashley
pythondev_help_Ashley_2019-03-13T18:55:55.520100
1,552,503,355.5201
13,258
pythondev
help
That's how you would do it for an exception
2019-03-13T18:56:03.520600
Ashley
pythondev_help_Ashley_2019-03-13T18:56:03.520600
1,552,503,363.5206
13,259
pythondev
help
i havent come across this before in 5 years of developing lol
2019-03-13T18:56:06.520700
Tasha
pythondev_help_Tasha_2019-03-13T18:56:06.520700
1,552,503,366.5207
13,260
pythondev
help
i have studied IOC container DI
2019-03-13T18:56:24.521400
Tasha
pythondev_help_Tasha_2019-03-13T18:56:24.521400
1,552,503,384.5214
13,261
pythondev
help
SOLId
2019-03-13T18:56:26.521600
Tasha
pythondev_help_Tasha_2019-03-13T18:56:26.521600
1,552,503,386.5216
13,262
pythondev
help
You haven't come across inheritance in 5 years of development?
2019-03-13T18:56:27.521800
Ashley
pythondev_help_Ashley_2019-03-13T18:56:27.521800
1,552,503,387.5218
13,263
pythondev
help
etc
2019-03-13T18:56:29.522000
Tasha
pythondev_help_Tasha_2019-03-13T18:56:29.522000
1,552,503,389.522
13,264
pythondev
help
functional, erlang
2019-03-13T18:56:32.522200
Tasha
pythondev_help_Tasha_2019-03-13T18:56:32.522200
1,552,503,392.5222
13,265
pythondev
help
and i dont know how this works lol
2019-03-13T18:56:41.522400
Tasha
pythondev_help_Tasha_2019-03-13T18:56:41.522400
1,552,503,401.5224
13,266
pythondev
help
i understand inheritance
2019-03-13T18:56:55.522700
Tasha
pythondev_help_Tasha_2019-03-13T18:56:55.522700
1,552,503,415.5227
13,267
pythondev
help
solid principles
2019-03-13T18:56:59.522900
Tasha
pythondev_help_Tasha_2019-03-13T18:56:59.522900
1,552,503,419.5229
13,268
pythondev
help
etc
2019-03-13T18:57:00.523100
Tasha
pythondev_help_Tasha_2019-03-13T18:57:00.523100
1,552,503,420.5231
13,269
pythondev
help
but i dont understand how python Exceptions reach down to the child classes
2019-03-13T18:57:21.523600
Tasha
pythondev_help_Tasha_2019-03-13T18:57:21.523600
1,552,503,441.5236
13,270
pythondev
help
Oh, yeah, they don't
2019-03-13T18:58:42.526500
Ashley
pythondev_help_Ashley_2019-03-13T18:58:42.526500
1,552,503,522.5265
13,271
pythondev
help
The parent class can be completely unaware that it has descendants
2019-03-13T18:59:05.528000
Ashley
pythondev_help_Ashley_2019-03-13T18:59:05.528000
1,552,503,545.528
13,272
pythondev
help
I have read that Python's inheritance tree goes upwards untl the base class
2019-03-13T18:59:29.529900
Tasha
pythondev_help_Tasha_2019-03-13T18:59:29.529900
1,552,503,569.5299
13,273
pythondev
help
Python in the one checking that the exception that was raised inherits from any of the exception classes you want to catch
2019-03-13T18:59:39.530400
Ashley
pythondev_help_Ashley_2019-03-13T18:59:39.530400
1,552,503,579.5304
13,274
pythondev
help
They don't, and it isn't exception specific. When you had except parent it caught child because child inherited from parent. Python, via the mro, knows that
2019-03-13T18:59:53.530900
Clemmie
pythondev_help_Clemmie_2019-03-13T18:59:53.530900
1,552,503,593.5309
13,275
pythondev
help
It is the reverse if what you said really. Child knows it inherits from parent,but parent doesn't necessarily know what inherits from itself
2019-03-13T19:01:02.534200
Clemmie
pythondev_help_Clemmie_2019-03-13T19:01:02.534200
1,552,503,662.5342
13,276
pythondev
help
there's "old" style classes, and "new" style classes. I believe in Python 3, old style classes don't exist anymore, but basically, the difference is that in old style classes, they don't extend all the way up to the `object` class, and in new style classes, they do
2019-03-13T19:01:19.534900
Ashley
pythondev_help_Ashley_2019-03-13T19:01:19.534900
1,552,503,679.5349
13,277
pythondev
help
can you give me an example outside of Exceptions whereby python can expose a classes child /sub classes?
2019-03-13T19:01:31.535500
Tasha
pythondev_help_Tasha_2019-03-13T19:01:31.535500
1,552,503,691.5355
13,278
pythondev
help
that doesn't really happen often
2019-03-13T19:01:49.536300
Ashley
pythondev_help_Ashley_2019-03-13T19:01:49.536300
1,552,503,709.5363
13,279
pythondev
help
you'd have to implement that yourself
2019-03-13T19:01:53.536700
Ashley
pythondev_help_Ashley_2019-03-13T19:01:53.536700
1,552,503,713.5367
13,280
pythondev
help
So, effectively, when you did except parent, child says "I am a type of parent" and is caught
2019-03-13T19:01:59.537100
Clemmie
pythondev_help_Clemmie_2019-03-13T19:01:59.537100
1,552,503,719.5371
13,281
pythondev
help
like we said, the parent is unaware of the children
2019-03-13T19:02:05.537300
Ashley
pythondev_help_Ashley_2019-03-13T19:02:05.537300
1,552,503,725.5373
13,282
pythondev
help
ahh great thanks
2019-03-13T19:02:28.537900
Tasha
pythondev_help_Tasha_2019-03-13T19:02:28.537900
1,552,503,748.5379
13,283
pythondev
help
Using parent/child as the terms also confuses it a bit
2019-03-13T19:02:36.538300
Clemmie
pythondev_help_Clemmie_2019-03-13T19:02:36.538300
1,552,503,756.5383
13,284
pythondev
help
yeah
2019-03-13T19:02:44.538600
Ashley
pythondev_help_Ashley_2019-03-13T19:02:44.538600
1,552,503,764.5386
13,285
pythondev
help
super / sub classes
2019-03-13T19:03:11.539900
Tasha
pythondev_help_Tasha_2019-03-13T19:03:11.539900
1,552,503,791.5399
13,286
pythondev
help
<@Tasha> make a class that inherits from a few other classes, and then call `__mro__` on it (I think that's the attribute)
2019-03-13T19:03:15.540400
Ashley
pythondev_help_Ashley_2019-03-13T19:03:15.540400
1,552,503,795.5404
13,287
pythondev
help
ok cool!
2019-03-13T19:03:28.541000
Tasha
pythondev_help_Tasha_2019-03-13T19:03:28.541000
1,552,503,808.541
13,288
pythondev
help
that might clear it up a bit
2019-03-13T19:03:29.541300
Ashley
pythondev_help_Ashley_2019-03-13T19:03:29.541300
1,552,503,809.5413
13,289
pythondev
help
Like apple knows it is a fruit, and will respond as such, but fruit doesn't need to know what fruits there are
2019-03-13T19:03:34.541600
Clemmie
pythondev_help_Clemmie_2019-03-13T19:03:34.541600
1,552,503,814.5416
13,290
pythondev
help
thats it!
2019-03-13T19:03:45.541900
Tasha
pythondev_help_Tasha_2019-03-13T19:03:45.541900
1,552,503,825.5419
13,291
pythondev
help
haha now i understand
2019-03-13T19:03:49.542100
Tasha
pythondev_help_Tasha_2019-03-13T19:03:49.542100
1,552,503,829.5421
13,292
pythondev
help
So python must be looking at any class that extends from Exception , right down the tree of subclasses?
2019-03-13T19:04:40.543800
Tasha
pythondev_help_Tasha_2019-03-13T19:04:40.543800
1,552,503,880.5438
13,293
pythondev
help
yep. Python basically sees you're trying to catch `Fruit`, and goes `if Fruit in Apple.__mro__: # actually catch it`
2019-03-13T19:04:41.543900
Ashley
pythondev_help_Ashley_2019-03-13T19:04:41.543900
1,552,503,881.5439
13,294
pythondev
help
oh, no it doesn't really care about all classes that extend from exception
2019-03-13T19:05:10.544600
Ashley
pythondev_help_Ashley_2019-03-13T19:05:10.544600
1,552,503,910.5446
13,295
pythondev
help
it pretty much does `if Fruit in Apple.__mro__: # actually catch it`
2019-03-13T19:05:33.545200
Ashley
pythondev_help_Ashley_2019-03-13T19:05:33.545200
1,552,503,933.5452
13,296
pythondev
help
ahh so its looks here: SubClassException(Exception) &lt; -------- here
2019-03-13T19:05:40.545600
Tasha
pythondev_help_Tasha_2019-03-13T19:05:40.545600
1,552,503,940.5456
13,297
pythondev
help
because it saw `catch Fruit`
2019-03-13T19:05:44.545700
Ashley
pythondev_help_Ashley_2019-03-13T19:05:44.545700
1,552,503,944.5457
13,298
pythondev
help
kind of
2019-03-13T19:05:55.545900
Ashley
pythondev_help_Ashley_2019-03-13T19:05:55.545900
1,552,503,955.5459
13,299
pythondev
help
MRO is a lot more complex than what's listed in there
2019-03-13T19:06:06.546200
Ashley
pythondev_help_Ashley_2019-03-13T19:06:06.546200
1,552,503,966.5462
13,300
pythondev
help
ok
2019-03-13T19:06:07.546400
Tasha
pythondev_help_Tasha_2019-03-13T19:06:07.546400
1,552,503,967.5464
13,301
pythondev
help
is this in Java?
2019-03-13T19:06:17.546800
Tasha
pythondev_help_Tasha_2019-03-13T19:06:17.546800
1,552,503,977.5468
13,302
pythondev
help
watch Super Considered Super, and it should explain it pretty well
2019-03-13T19:06:34.547600
Ashley
pythondev_help_Ashley_2019-03-13T19:06:34.547600
1,552,503,994.5476
13,303
pythondev
help
Java doesn't have this
2019-03-13T19:06:40.548000
Ashley
pythondev_help_Ashley_2019-03-13T19:06:40.548000
1,552,504,000.548
13,304
pythondev
help
Java actually has what I think is called a "death triangle of inheritance"
2019-03-13T19:06:56.548900
Ashley
pythondev_help_Ashley_2019-03-13T19:06:56.548900
1,552,504,016.5489
13,305
pythondev
help
or something like that
2019-03-13T19:07:08.549400
Ashley
pythondev_help_Ashley_2019-03-13T19:07:08.549400
1,552,504,028.5494
13,306
pythondev
help
I wondered how my boss new how this works, he isnt great at all at Python, he comes from Java/ ruby
2019-03-13T19:07:23.550000
Tasha
pythondev_help_Tasha_2019-03-13T19:07:23.550000
1,552,504,043.55
13,307
pythondev
help
basically, multiple inheritance can go awry very quickly in Java
2019-03-13T19:07:27.550400
Ashley
pythondev_help_Ashley_2019-03-13T19:07:27.550400
1,552,504,047.5504
13,308
pythondev
help
Well, does java have what exactly?
2019-03-13T19:07:44.550800
Clemmie
pythondev_help_Clemmie_2019-03-13T19:07:44.550800
1,552,504,064.5508
13,309
pythondev
help
Python avoids that problem with MRO
2019-03-13T19:07:46.550900
Ashley
pythondev_help_Ashley_2019-03-13T19:07:46.550900
1,552,504,066.5509
13,310
pythondev
help
I just wondered how he knew straight away i can just use our custom parent exception class and all the sub classes would be caught as well
2019-03-13T19:08:35.551800
Tasha
pythondev_help_Tasha_2019-03-13T19:08:35.551800
1,552,504,115.5518
13,311
pythondev
help
its really a head teaser
2019-03-13T19:08:53.552000
Tasha
pythondev_help_Tasha_2019-03-13T19:08:53.552000
1,552,504,133.552
13,312
pythondev
help
brain teaser, rather lol
2019-03-13T19:09:00.552300
Tasha
pythondev_help_Tasha_2019-03-13T19:09:00.552300
1,552,504,140.5523
13,313
pythondev
help
but thanks guys
2019-03-13T19:09:18.552500
Tasha
pythondev_help_Tasha_2019-03-13T19:09:18.552500
1,552,504,158.5525
13,314
pythondev
help
explained very well
2019-03-13T19:09:22.552700
Tasha
pythondev_help_Tasha_2019-03-13T19:09:22.552700
1,552,504,162.5527
13,315
pythondev
help
im going to quiz him tomorrow on the technicals of this
2019-03-13T19:09:33.553000
Tasha
pythondev_help_Tasha_2019-03-13T19:09:33.553000
1,552,504,173.553
13,316
pythondev
help
ah found it
2019-03-13T19:09:41.553400
Ashley
pythondev_help_Ashley_2019-03-13T19:09:41.553400
1,552,504,181.5534
13,317
pythondev
help
im sure he would have no idea or MRO
2019-03-13T19:09:42.553500
Tasha
pythondev_help_Tasha_2019-03-13T19:09:42.553500
1,552,504,182.5535
13,318
pythondev
help
Java has what's called the "deadly diamond of death" (I'm not making that up)
2019-03-13T19:10:02.554100
Ashley
pythondev_help_Ashley_2019-03-13T19:10:02.554100
1,552,504,202.5541
13,319
pythondev
help
]haha
2019-03-13T19:10:16.554300
Tasha
pythondev_help_Tasha_2019-03-13T19:10:16.554300
1,552,504,216.5543
13,320