Skip to content

add other bytes method #847

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

Merged
merged 26 commits into from
May 3, 2019
Merged

add other bytes method #847

merged 26 commits into from
May 3, 2019

Conversation

jgirardet
Copy link
Contributor

some refactoring
some more methods

@codecov-io
Copy link

codecov-io commented Apr 18, 2019

Codecov Report

Merging #847 into master will increase coverage by 1.31%.
The diff coverage is 69.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #847      +/-   ##
==========================================
+ Coverage   62.89%   64.21%   +1.31%     
==========================================
  Files          88       88              
  Lines       14547    15172     +625     
  Branches     3288     3405     +117     
==========================================
+ Hits         9150     9743     +593     
+ Misses       3238     3178      -60     
- Partials     2159     2251      +92
Impacted Files Coverage Δ
vm/src/obj/objmemory.rs 82.35% <100%> (+46.63%) ⬆️
vm/src/obj/objsequence.rs 54.37% <50%> (+0.75%) ⬆️
vm/src/obj/objbyteinner.rs 68.9% <69.16%> (-0.75%) ⬇️
vm/src/obj/objbytes.rs 73.73% <72.3%> (+3.49%) ⬆️
vm/src/obj/objcomplex.rs 74.57% <0%> (-8.19%) ⬇️
vm/src/pyobject.rs 78.46% <0%> (-1.86%) ⬇️
vm/src/symboltable.rs 54.12% <0%> (-1.23%) ⬇️
vm/src/obj/objtype.rs 73.3% <0%> (-0.49%) ⬇️
vm/src/compile.rs 76.82% <0%> (-0.34%) ⬇️
vm/src/obj/objdict.rs 72.98% <0%> (-0.17%) ⬇️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19be5c9...5d13dae. Read the comment docs.

@jgirardet
Copy link
Contributor Author

jgirardet commented Apr 22, 2019

I have : split and rsplit, expandstab , partition/reparition, spitlines, zfill, replace
waiting in another branch. do you want I push it now, or do you prefer review just this one which is already big enough ?

@coolreader18
Copy link
Member

I think maybe save that for another PR, yes.

@coolreader18 coolreader18 self-assigned this Apr 22, 2019
Copy link
Contributor

@palaviv palaviv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work. This is a very big PR so I have not yet finished going over all the code.
I am having hard time with the parameters parsing. I think that finding some kind of abstraction to make it simpler would be great.

#[pyarg(positional_only, optional = false)]
sub: PyObjectRef,
#[pyarg(positional_only, optional = true)]
start: OptionalArg<PyObjectRef>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be PyIntRef.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be Int or None so I have to accept PyObjectRef

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do OptinalArg<PyIntRef>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe OptionalArg<Option<PyIntRef>>? I'm not sure if Option is FromArgs yet, but it should be the specified type or Python None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using OptionalArg<Option<PyIntRef>>, you mean this implementation in impl block (line 126)?

let start = match self.start {
            OptionalArg::Present(Some(int)) => Some(int.as_bigint().clone()),
            _ => None,
        };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let it for now.

let start = match self.start {
            OptionalArg::Present(Some(int)) => Some(int.as_bigint().clone()),
            _ => None,
        };

instead of

let start = match self.start.into_option() {
            Some(Some(int)) => Some(int.as_bigint().clone()),
            _ => None,
        };

using into_option() isn't much shorter and I find it less explicit. what do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They both look great to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rust clippy tool would probably suggest to use something like this:

let start = if let Some(Some(int)) = self.start.into_option() {
   Some(int.as_bigint().clone())
} else {
   None
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use clippy and non suggestion about it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's especially handy when you have a match with only two options (basically an if-else case).

@jgirardet jgirardet mentioned this pull request Apr 25, 2019
@palaviv
Copy link
Contributor

palaviv commented Apr 29, 2019

Sorry for the late response @jgirardet. I will try and finish going over all the PR soon.

@jgirardet
Copy link
Contributor Author

np @palaviv
It took time but I finally understood how it works. thank for your help.
I added it :

impl<B: PyValue> TryFromObject for Either<PyByteInner, PyRef<B>>
and
impl TryFromObject for PyByteInner 

it's far better like it.

@palaviv
Copy link
Contributor

palaviv commented Apr 30, 2019

This looks way better :).
I think you can do TryFromObject for PyByteInner and use Either default one instead of creating one for Either<PyByteInner, PyRef<B>>.

@jgirardet
Copy link
Contributor Author

PyByteInner doesn't implement PyValue so I can't use the default Either

@windelbouwman
Copy link
Contributor

I think this change is ready for merge now? Thank you for reviewing the change.

@windelbouwman windelbouwman merged commit daf7042 into RustPython:master May 3, 2019
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

Successfully merging this pull request may close these issues.

5 participants