Skip to content

Complete support for bytes paths in nt#992

Merged
slozier merged 6 commits intoIronLanguages:masterfrom
BCSharp:nt
Dec 1, 2020
Merged

Complete support for bytes paths in nt#992
slozier merged 6 commits intoIronLanguages:masterfrom
BCSharp:nt

Conversation

@BCSharp
Copy link
Copy Markdown
Member

@BCSharp BCSharp commented Oct 21, 2020

No description provided.

@BCSharp BCSharp marked this pull request as draft October 21, 2020 19:21
Copy link
Copy Markdown
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

I know it's still marked as draft, but here are my notes.

Comment thread Src/IronPython.Modules/nt.cs Outdated
Comment on lines +511 to +512
foreach (object name in listdir(context, _filesystemEncoding.GetString(path.AsMemory().Span))) {
ret.AddNoLock(Bytes.Make(_filesystemEncoding.GetBytes((string)name)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use your ToFsString and ToFsBytes helpers?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, a remnant from pre-helpers time.

Comment thread Src/IronPython.Modules/nt.cs Outdated
System.Text.StringBuilder sb = null;
if (!PythonOps.TryGetEnumerator(context, args, out argsEnumerator)) {
throw PythonOps.TypeError("args parameter must be sequence, not {0}", DynamicHelpers.GetPythonType(args));
throw PythonOps.TypeError("args parameter must be sequence, not {1}", DynamicHelpers.GetPythonType(args));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure why this changed from {0} to {1}?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wow, no idea why...

Comment thread Src/IronPython.Modules/nt.cs Outdated
Comment on lines +1492 to +1494
times = kvp.Value == null ? null
: args[0] is PythonTuple pt2 ? pt2
: throw PythonOps.TypeError("utime: 'times' must be either a 2-value tuple (atime, mtime) or None");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should args[0] here be kvp.Value? Maybe wrap the logic in a local function:

static PythonTuple GetTimes(object val) {
    return val == null ? null
        : val is PythonTuple pt ? pt
        : throw PythonOps.TypeError("utime: 'times' must be either a 2-value tuple (atime, mtime) or None");
}

I guess we could also do the length check on the tuple in there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK. In general, I am still working on the keyword/default parameter handling and am musing about some generic, multipurpose mechanism that will cut though so much ceremony that is now required. The \u00F8 seems not to work anymore since Python 3 allows Unicode letters in identifiers. But perhaps I will start with something simpler, like #882.

Comment thread Src/IronPython.Modules/nt.cs Outdated
private static Bytes ToFsBytes(this string s) => Bytes.Make(_filesystemEncoding.GetBytes(s));

private static Bytes ToFsBytes(this IBufferProtocol bp) {
// TODO: DeprecationWarning starting from Python 3.7
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would be fine with adding the deprecation warning right away (if it doesn't cause testing failures).

@BCSharp
Copy link
Copy Markdown
Member Author

BCSharp commented Oct 23, 2020

Thanks for early feedback!

@slozier
Copy link
Copy Markdown
Contributor

slozier commented Nov 30, 2020

I think this may solve some of the failures in test_glob.

@BCSharp
Copy link
Copy Markdown
Member Author

BCSharp commented Dec 1, 2020

I have kept it on hold because some things can get simplified once we have support for keyword-only arguments. But since I am preoccupied with other stuff right now, I can't say when this will be. So if it helps, this PR can be merged as is. I can always revisit it later on.

@BCSharp BCSharp marked this pull request as ready for review December 1, 2020 01:44
@slozier
Copy link
Copy Markdown
Contributor

slozier commented Dec 1, 2020

Thanks. I'll merge it in as-is. Better to have incremental progress than wait indefinitely. 😄

@slozier slozier merged commit 9498c0d into IronLanguages:master Dec 1, 2020
@BCSharp BCSharp deleted the nt branch December 9, 2020 22:00
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.

2 participants